#include <stdio.h>

void AddNumberToPostfix(char matrixInfix[30][30], char matrixPostfix[30][30], int i, int* topPostfix)
{
    int j;

    (*topPostfix)++;

    for (j=0; matrixInfix[i][j]!='\0'; j++);
    {
        //char c = matrixInfix[i][j];
        matrixPostfix[(*topPostfix)][j] = matrixInfix[i][j];
        printf("%c", matrixInfix[i][j]);
    }

}

int IsNumber(char matrixInfix[30][30], int i)
{
    if( matrixInfix[i][0]>47 && matrixInfix[i][0]<58 )
    {
        return 1;
    }
    else if ( ( matrixInfix[i][0] == '-' )&&( matrixInfix[i][1]>47 && matrixInfix[i][1]<58 ) )
    {
        return 1;
    }
    else return 0;
}

void ConvertToPostfix(char matrixInfix[30][30], char matrixPostfix[30][30])
{
    int i = 0;
    int topStack, topPostfix;

    while(matrixInfix[i][0] != '\0')
    {
        if(IsNumber(matrixInfix, i))
        {
            AddNumberToPostfix(matrixInfix, matrixPostfix, i, &topPostfix);
            i++;
        }
    }
}

void TestIsNumber()
{
    char maxtrix[30][30];
    maxtrix[0][0] = '4';
    if (IsNumber(maxtrix, 0))
    {
        printf("test key 1: true \n");
    }
    else
    {
        printf("test key 1: false \n");
    }

    maxtrix[0][0] = '-';
    maxtrix[0][1] = '3';
    if (IsNumber(maxtrix, 0))
    {
        printf("test key 2: true \n");
    }
    else
    {
        printf("test key 2: false \n");
    }
}

int TestAddNumberToPostfix()
{
    int i = 3, j, topPostfix = 4;
    char infix[30][30];
    infix[3][0] = '-';
    infix[3][1] = '3';
    infix[3][2] = '.';
    infix[3][3] = '5';
    infix[3][4] = '\0';
    char postfix[30][30];

    AddNumberToPostfix(infix, postfix, 3, &topPostfix);
    if (topPostfix!= 5)
    {
        printf("test key 3: false \n");
        return 0;
    }
    for (j = 0; j < 4; j++)
    {
        //printf("%c", postfix[topPostfix][j]);
        if(infix[3][j] != postfix[topPostfix][j])
        {
            //printf("test key 3: false \n");
        }
    }
    //printf("test key 3: true \n");
    return 1;

}

int main()
{
    // TEST IsNumber FUNCTION
    TestIsNumber();
    // TEST IsNumber FUNCTION

    // TEST AddNumberToPostfix FUNCTION
    TestAddNumberToPostfix();
    // TEST AddNumberToPostfix FUNCTION
    getch();

}
